// ActionScript file
import com.helloniu.model.ChatModel;
import com.helloniu.controller.ChatController;
import com.helloniu.controller.UserListController;
import com.helloniu.fl.util.Tool;

private var oldInfo:String = "";

private function initApp(e:*):void {
	UserListController.getIns().addView(this);
	ChatController.getIns().addView(this);
}

public function updateModel():void {
	var model:ChatModel = ChatController.getIns().getModel() as ChatModel;
	
	var newInfo:String = model.getChatString();
	
	// users does not chnage
	if(oldInfo == newInfo) {
		return;
	}

	oldInfo = newInfo;
	
	populate();
}

private function populate():void {
	chatLog.text = oldInfo;
}

private function chatKeyUp(evt:KeyboardEvent):void {    
	if(evt.keyCode == Keyboard.ENTER) {
    	var str:String = chatTxt.text;
                
    	ChatController.getIns().addChatString(str);
    	chatTxt.text = "";        
    }
}
